FHIRPath
API
evaluate
Returns a JS object/primitive based on the evaluation.
evaluate(
expression: string,
ctx: unknown,
options?: Options
): NonNullable<unknown>[]
evaluateWithMeta
Returns a @iguhealth/meta-value singular value which contains data along with metadata about the evaluation.
function evaluateWithMeta(
expression: string,
ctx: unknown,
options?: Options,
): MetaValueSingular<NonNullable<unknown>>[];
Arguments
name | type | description |
---|---|---|
expression | string | FHIRPath expression to evaluate. |
ctx | unknown | The context which the fhirpath is being evaluated from (sets $this context). |
options | Object | Includes variables and metadata deriviation functions. |
options.variables | Object | Function | If an object is Record<variableName, variableValue> else (variableName)=> variableValue. |
options.meta | Object | MetaInformation used to zip metadata with value. Used in type functions and operators. |
options.meta.type | string | Root type for ctx. |
options.meta.getSD | (fhir_version: FHIRVersion, type: string) => StructureDefinition | Returns a StructureDefinition based on type passed in. |
Usage
import * as fhirpath from "@iguhealth/fhirpath";
// Default returns javascript object.
expect(fhirpath.evaluate("4 + 5", {})).toEqual([9]);
expect(fhirpath.evaluate("$this.test + 2 * 4", { test: 4 })).toEqual([12]);
// Evaluation with metavalue return (returns value in addition to meta information.)
expect(
evaluateWithMeta(
"$this.name",
{
resourceType: "Patient",
name: [{ given: ["bob"], family: "jameson" }],
},
{
meta: {
type: "Patient",
getSD: (fhirVersion, type: code) => {
const foundSD = sds.find((sd) => sd.type === type);
return foundSD;
},
},
},
).map((v) => v.meta()?.type),
).toEqual(["HumanName"]);